package com.aaa.test1.dao.impl;



import com.aaa.test1.dao.StudentDAO;
import com.aaa.test1.entity.Student;
import com.aaa.test1.util.DAOUtil;

import java.util.List;
import java.util.Map;

public class StudentDAOImpl implements StudentDAO {
    @Override
    public List<Map<String, Object>> Select() {
        String sql =" select * from student";
        return DAOUtil.query(sql);
    }

    @Override
    public int delStudent(String id) {
        String sql = "delete from student where id = ?";
        return DAOUtil.update(sql,id);
    }

    @Override
    public int addStudent(Student student) {
        String sql ="insert into student values(?,?,?,?)";
        return DAOUtil.update(sql,student.getId(),student.getName(),student.getAge(),student.getAddress());
    }

    @Override
    public Map<String, Object>getStu(String id) {
        String sql =" select * from  student  where  id =?";
        List<Map<String, Object>> query = DAOUtil.query(sql,id);
        if (query.size()>0) {
            return query.get(0);
        }
        return null;
    }

    @Override
    public int updateStudent(Student student) {
        String sql=" update student set name=?, age=?,address=? where id =?";
        return DAOUtil.update(sql,student.getName(),student.getAge(),student.getAddress(),student.getId());
    }
}
